﻿//退回
function goback(hardid) {
    if (window.confirm('你确定要退回吗？')) {
        $.ajax({
            type: "post",
            url: "/ashx/HardWare.ashx",
            data: {
                rType: 'goback'
                   , hardid: hardid
            },
            error: function (XmlHttpRequest, textStatus, errorThrown) {
                alert(XmlHttpRequest.status);
                alert("提交失败！");
            },
            success: function (msg) {
                location.reload();
            }
        });
        return true;
    } else {
        //alert("取消");
        return false;
    }
}

function dele(obj) {
    $(obj).parent().parent().remove();
}


function cancel() {
    location.reload();
}


//销售询价
function gocheck(hardid) {
    $("#hidHardid").val(hardid);
    //取值
    $.ajax({
        type: "post",
        url: "/ashx/HardWare.ashx",
        data: {
            rType: 'm'
                   , mid: hardid
                   , other: "isatt"
                   , eType: "D"
        },
        error: function (XmlHttpRequest, textStatus, errorThrown) {
            alert(XmlHttpRequest.status);
            alert("提交失败！");
        },
        success: function (msg) {
            //值显示
            var o = eval('(' + msg + ')');
            $("#lblno").html(o.hardwareno);
            $("#lblcjo").html(o.cjono);
            $("#lblload").html(o.loadno);
            $("#lblcumname").html(o.cumname);
            $("#lblman").html(o.saleman);
            $("#lblcjoremark").html(o.cjoremark);
            $("#lblcolldate").html(o.wrldate);
            $("#lblcount").html(o.boxcount);
            $("#lblbcity").html(o.bcity);
            $("#lblgcity").html(o.gcity);
            $("#lblinitremark").html(o.initremark);
            $("#lblhardremark").html(o.hardremark);
            $("#txttallyremark").val(o.tallyremark);
            $("#lblfinishdate").html(o.hardwarefinish);
            $("#lblgodate").html(o.inspectiondate);


            //附件列表

            var html = "";
            $.each(o.attlist, function (index, v) {
                html = html + "<a>" + v.AttacheName + "</a>;";
            });
            $("#txtAttList").html(html);

            html = "<tr><td style='display:none;width:0px;'></td><td>下家名</td><td>邮件地址</td><td>操作</td><td><td></tr>";
            $.each(o.emaillist, function (index, v) {
                html = html + "<tr>";
                html = html + "<td style='display:none;width:0px;'>";
                html = html + v.linkman;
                html = html + "</td>";
                html = html + "<td>";
                html = html + v.companyname;
                html = html + "</td>";
                html = html + "<td>";
                html = html + v.email;
                html = html + "</td>";
                html = html + "<td><a onclick='dele(this)'>删除<a></td>";
                html = html + "</td>";
                html = html + "<td style='display:none;width:0px;'>" + v.id + "</td>";

                html = html + "</tr>";
            });
            $("#TabEmailList").html(html);

            var myDate = new Date();
            $("#lbloutstime").html(myDate.toLocaleDateString());
            //弹出框
            $("#tabreord").dialog({
                width: 700,
                height: 300,
                resizable: false,
                position: 'center',
                title: "销售询价",
                modal: true
            });



            $('#tMialMans').tagsInput({
                width: '200px',
                height: '100px',
               
                autocomplete_url: '/ashx/Email.ashx?eType=I&key='
            });

            $('#cMailMans').tagsInput({
                width: '200px',
                height: '100px',
                autocomplete_url: '/ashx/Email.ashx?eType=CC&key='
            });

        }
    });


}



//询价弹出提交
function gocheckSubmit() {
    var edata = $("#tMialMans").val();

        var myDate = new Date();
        var emailtitle = "报价";
        var emailcontext = $("#txtEmailContent").val();
        var emailist = $("#tMialMans").val();
        var cclist = $("#cMailMans").val();
//        var trlist = $("#TabEmailList").children("tr");
//        var strjson = "[";
//        var i = 0;
//        $("#TabEmailList").find("tr").each(function () {
//            var tdArr = $(this).children();
//            if (i > 0) {
//                if (i > 1)
//                    strjson = strjson + ",";
//                strjson = strjson + "{";

//                strjson = strjson + '"flag1":"' + tdArr.eq(0).html() + '",'; //flag1 
//                strjson = strjson + '"tname":"' + tdArr.eq(1).html() + '",'; //flag1 
//                strjson = strjson + '"email":"' + tdArr.eq(2).html() + '",'; //flag1 
//                strjson = strjson + '"id":' + tdArr.eq(4).html() + "}"; //id

//            }
//            i++;
//        });
//        strjson = strjson + "]";
//        if (strjson.length > 10) {
//            
//            emaillist = strjson;
//        } else {
//            return;
//        }

        $.ajax({
            type: "post",
            url: "/ashx/HardWare.ashx",
            data: {
                rType: "Hard"
                , hardid: $("#hidHardid").val()
                , step1: 5
                ,cclist:cclist
                , emaillist: $("#tMialMans").val()
                , cclist: $("#cMailMans").val()
                , context: emailtitle
                , emailtitle: emailtitle
                , eType: "D"

            },
            error: function (XmlHttpRequest, textStatus, errorThrown) {
                alert(XmlHttpRequest.status);
                alert("提交失败！");
            },
            success: function (msg) {
                alert("已经送检");
                location.reload();
            }
        });
   
    

}

$(document).ready(function () {

    $("#rdoC,#rdoSale").click(function () {
        if ($(this).attr('id') == 'rdoC') {
            $("#gotype").val("3");
        }
        else if ($(this).attr('id') == 'rdoSale') {
            $("#gotype").val("4");
        }

    });

    $('#tab').dataTable({ "oLanguage":
                 { "sUrl": "/jquery/jquery.dataTable.cn.txt" },
        "bJQueryUI": true,
        "sPaginationType": "full_numbers",
        'bPaginate': true,
        "bProcessing": true,
        "iDisplayLength": 20,
        "bSort": true,
        "aaSorting": [[0, "desc"]]
    });


    $("#tabreord").hide();


});
